

using System;
using System.Collections.Generic;
using System.Text;
using EntityLayer;
using System.Data;
using DataAccessLayer;
using InfraStructureLayer;

namespace DataLayer
{
	public class datEntries
	{
		public datEntries()
		{
		}

        #region  Code Factory Generated Methods
        public void DeleteEntriesByEntryId(entEntries parEntEntries, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pEntryId", parEntEntries.EntryId);
            parDbConnector.ExecuteNonQuery("DeleteEntriesByEntryId", insDbParamCollection);
        }
        public void InsertEntries(entEntries parEntEntries, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pPublishDate", parEntEntries.PublishDate);
            insDbParamCollection.Add("@pAllowComments", parEntEntries.AllowComments);
            insDbParamCollection.Add("@pInsertDate", parEntEntries.InsertDate);
            insDbParamCollection.Add("@pEntryDescription", parEntEntries.EntryDescription);
            insDbParamCollection.AddOutput("@pEntryId", DbType.Int32);
            parDbConnector.ExecuteNonQuery("InsertEntries", insDbParamCollection);
            parEntEntries.EntryId = Convert.ToInt32(insDbParamCollection.GetOutPutParameter().Value);
        }
        public void UpdateEntriesByEntryId(entEntries parEntEntries, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pEntryId", parEntEntries.EntryId);

            insDbParamCollection.Add("@pPublishDate", parEntEntries.PublishDate);
            insDbParamCollection.Add("@pAllowComments", parEntEntries.AllowComments);
            insDbParamCollection.Add("@pInsertDate", parEntEntries.InsertDate);
            insDbParamCollection.Add("@pEntryDescription", parEntEntries.EntryDescription);
            parDbConnector.ExecuteNonQuery("UpdateEntriesByEntryId", insDbParamCollection);
        }
        public DataTable SelectEntries(DbConnector parDbConnector)
        {

            return parDbConnector.ExecuteDataTable("SelectEntries", null);
        }
        public void SelectEntriesByEntryId(entEntries parEntEntries, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pEntryId", parEntEntries.EntryId);
            DataTable insDataTable = new DataTable();
            insDataTable = parDbConnector.ExecuteDataTable("SelectEntriesByEntryId", insDbParamCollection);
            if (insDataTable.Rows.Count > 0)
            {
                if (insDataTable.Rows[0]["EntryId"] != DBNull.Value)
                {
                    parEntEntries.EntryId = Convert.ToInt32(insDataTable.Rows[0]["EntryId"]);
                }
                if (insDataTable.Rows[0]["PublishDate"] != DBNull.Value)
                {
                    parEntEntries.PublishDate = Convert.ToDateTime(insDataTable.Rows[0]["PublishDate"]);
                }
                if (insDataTable.Rows[0]["AllowComments"] != DBNull.Value)
                {
                    parEntEntries.AllowComments = Convert.ToBoolean(insDataTable.Rows[0]["AllowComments"]);
                }
                if (insDataTable.Rows[0]["InsertDate"] != DBNull.Value)
                {
                    parEntEntries.InsertDate = Convert.ToDateTime(insDataTable.Rows[0]["InsertDate"]);
                }
                if (insDataTable.Rows[0]["EntryDescription"] != DBNull.Value)
                {
                    parEntEntries.EntryDescription = insDataTable.Rows[0]["EntryDescription"].ToString();
                }
            }
        }
        
        #endregion
        public DataTable SelectEntriesLatest(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectEntriesLatest", insDbParamCollection);
        }
        public DataTable SelectEntryArchive(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectEntryArchive", insDbParamCollection);
        }
        public DataTable SelectEntryDates(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectEntryDates", insDbParamCollection);
        }
        public DataTable SelectEntriesBelongsToDates(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectEntriesBelongsToDates", insDbParamCollection);
        }

        public DataTable SelectEntryDatesByCategoryId(int categoryId,DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            insDbParamCollection.Add("@pCategoryId", categoryId);
            return parDbConnector.ExecuteDataTable("SelectEntryDatesByCategoryId", insDbParamCollection);
        }
        public DataTable SelectEntriesBelongsToDatesByCategoryId(int categoryId, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            insDbParamCollection.Add("@pCategoryId", categoryId);
            return parDbConnector.ExecuteDataTable("SelectEntriesBelongsToDatesByCategoryId", insDbParamCollection);
        }

        public DataTable SelectEntryDatesByPublishDate(entEntries parEntEntries,DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            insDbParamCollection.Add("@pMonth", parEntEntries.PublishDate.Month);
            insDbParamCollection.Add("@pYear", parEntEntries.PublishDate.Year);
            return parDbConnector.ExecuteDataTable("SelectEntryDatesByPublishDate", insDbParamCollection);
        }
        public DataTable SelectEntriesBelongsToDatesByPublishDate(entEntries parEntEntries, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            insDbParamCollection.Add("@pMonth", parEntEntries.PublishDate.Month);
            insDbParamCollection.Add("@pYear", parEntEntries.PublishDate.Year);
            return parDbConnector.ExecuteDataTable("SelectEntriesBelongsToDatesByPublishDate", insDbParamCollection);
        }
        public DataTable SelectEntriesByLanguageId(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectEntriesByLanguageId", insDbParamCollection);
        }
        public DataTable SelectEntriesLatestMainPage(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectEntriesLatestMainPage", insDbParamCollection);
        }
        public DataTable SelectEntriesByDateMainPage(entEntries parEntEntries, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            insDbParamCollection.Add("@pPublishDate", parEntEntries.PublishDate);
            return parDbConnector.ExecuteDataTable("SelectEntriesByDateMainPage", insDbParamCollection);
        }
	}
}